﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfHero;
using System.Windows.Media.Animation;

namespace WpfHeroResponse
{
    /// <summary>
    /// Interaction logic for HorizontalScroller.xaml
    /// </summary>
    public partial class HorizontalScroller : UserControl
    {
        WHEngine engine;

        public HorizontalScroller()
        {
            DataContextChanged += delegate { engine = ((WHEngine)DataContext); };
            InitializeComponent();
        }

        public void Start()
        {
            App.DoEvents();

            DoubleAnimation da = new DoubleAnimation
            {
                From = 0,
                To = (grid.ActualWidth * -1) + stackPanel.Margin.Left,
                Duration = new Duration(engine.EndOfSong)
            }; //-1 * (grid.ActualWidth), grid.ActualWidth / GemSizeConverter.MillisecondsPerPixel);

            stackPanel.RenderTransform = new TranslateTransform();
            stackPanel.RenderTransform.BeginAnimation(TranslateTransform.XProperty, da);
        }
    }
}
